package com.tangbuzhi.singleton;

/**
 * Created by admin on 2017/10/11.
 */
public class Singleton4 {
    /**
     * 第一次加载Singleton4类时，并不会初始化sInstance,只有第一次调用getInstance时，虚拟机才会加载SingletonHolder并初始化sInstance
     * 这样不仅能确保线程安全，也能保证Singleton4类的唯一性。所以推荐使用静态内部类单例模式
     */
    private Singleton4() {
    }

    private static Singleton4 instance;

    public static Singleton4 getInstance() {
        return SingletonHolder.sInstance;
    }

    private static class SingletonHolder {
        private static final Singleton4 sInstance = new Singleton4();
    }
}
